package flst.ipiweb.proxy;

import java.util.List;

import flst.ipiweb.service.ServiceAdministrateur;
import flst.ipiweb.service.ServiceAdministrateurAbstract;
import flst.ipiweb.transverse.Administrateur;
import flst.ipiweb.transverse.IPIException;

public class ServiceAdministrateurProxy extends ServiceAdministrateurAbstract{
	

	public ServiceAdministrateur serviceAdministrateur;
	public Boolean isSuper;
	
	public ServiceAdministrateurProxy(Boolean isSuper){
		this.isSuper = isSuper;
		this.serviceAdministrateur = new ServiceAdministrateur();
	}
	
	@Override
	public void createAdministrateur(Administrateur admin) throws IPIException {
		if(this.isSuper)
		{
			serviceAdministrateur.createAdministrateur(admin);
		}
		else
		{
			throw new IPIException("Admin.noRights");
		}
	}
	
	@Override
	public List<Administrateur> listAdministrateur() throws IPIException {
		if(this.isSuper)
		{
			List<Administrateur> listAdmin = serviceAdministrateur.listAdministrateur();
			return listAdmin;
		}
		else
		{
			throw new IPIException("Admin.noRights");
		}
	}
	
	@Override
	public void updateAdministrateur(Administrateur admin) throws IPIException {
		if(this.isSuper)
		{
			serviceAdministrateur.updateAdministrateur(admin);
		}
		else
		{
			throw new IPIException("Admin.noRights");
		}
	}
	
	@Override
	public void deleteAdministrateur(Administrateur admin) throws IPIException {
		if(this.isSuper)
		{
			serviceAdministrateur.deleteAdministrateur(admin);
		}
		else
		{
			throw new IPIException("Admin.noRights");
		}
	}
	
	
	@Override
	public Administrateur getAdministrateurById(int idUser) throws IPIException {
		if(this.isSuper)
		{
			return serviceAdministrateur.getAdministrateurById(idUser);
		}
		else
		{
			throw new IPIException("Admin.noRights");
		}
	}

}
